// Tags:
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 1e2 + 5, M = 16;
int n, m, f[N][1 << M], fee[N], c[N][1 << M];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("life.in", "r", stdin);
  freopen("life.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &fee[i]);
    for (int j = 0, lim, tmp; j < m; ++j) {
      scanf("%d", &tmp);
      lim = 1 << m;
      for (int k = 0; k < lim; ++k)
        if ((k >> j) & 1) c[i][k] += tmp;
    }
  }
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 1, lim; i <= n; ++i) {
    lim = 1 << m;
    for (int j = 0; j < lim; ++j) { f[i][j] = fee[i] + c[i][j]; }
  }
  for (int i = 1, lim; i <= n; ++i) {
    lim = 1 << m;
    for (int j = 0; j < lim; ++j) {
      f[i][j] = std::min(f[i][j], f[i - 1][j]);
      for (int k = j; k; k = j & (k - 1)) {
        f[i][j] = std::min(f[i][j], f[i - 1][k] + fee[i] + c[i][j ^ k]);
      }
    }
  }
  printf("%d", f[n][(1 << m) - 1]);
  return 0;
}